package com.pubg.information.controller;

import com.pubg.information.bean.Members;
import com.pubg.information.service.PersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class PersonalController {
    @Autowired
    PersonalService personalService;

    @RequestMapping(value = "/modifying")
    public ModelAndView modifying(HttpSession session){
        String acct = (String) session.getAttribute("userAccount");
        ModelAndView modelAndView = new ModelAndView("modifying");
        modelAndView.addObject("memb",personalService.getMembers(acct));
        return modelAndView;
    }

    @RequestMapping(value = "/modifying/upload")
    public ModelAndView modifiyMember(
                                @RequestParam("name")String name,
                                @RequestParam("age")String age,
                                @RequestParam("birthday")String birthday,
                                @RequestParam("phone")String phone,
                                HttpSession session){
        ModelAndView modelAndView = new ModelAndView("personal");
        String account = (String) session.getAttribute("userAccount");

        personalService.updMembers(name,phone,birthday,age,account);
        Members memb = personalService.getMembers(account);

        modelAndView.addObject("memb",memb);

        return modelAndView;
    }

    @RequestMapping(value = "/personal")
    public ModelAndView getpersonl(HttpSession session){
        String account = (String) session.getAttribute("userAccount");
        Members memb = personalService.getMembers(account);

        ModelAndView modelAndView = new ModelAndView("personal");
        modelAndView.addObject("memb",memb);

        return modelAndView;
    }
}
